package com.zys.el.user.quartz;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.zys.el.common.utils.JsonUtils;
import com.zys.el.user.config.po.SynthesizeResult;
import com.zys.el.user.po.User;
import com.zys.el.user.service.ISynthesizeService;
import com.zys.el.user.service.IUserService;
import lombok.SneakyThrows;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;
import java.util.List;

public class SynthesizeQuaetz extends QuartzJobBean {

    @Resource
    private ISynthesizeService service;
    @Resource
    private IUserService userService;
    @Resource
    private RedisTemplate redisTemplate;

    @SneakyThrows
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        List<User> list = userService.list();

        System.out.println("排行榜数据加载开始！！！");
        for (User user : list) {
            SynthesizeResult synthesizeByForth = service.getSynthesizeByForth(user.getId());
            synthesizeByForth.setReadySize(service.getSynthesizeByReady());

            redisTemplate.opsForValue().set("SY" +user.getId(),JSON.toJSONString(synthesizeByForth));
        }
        System.out.println("排行榜数据加载结束！！！");

    }
}
